#ifndef _EK_PIPE_H_
#define _EK_PIPE_H_

#define PIPE_BUFSIZE (PAGE_SIZE - 4 - sizeof(struct mutex_t))

struct pipe_t
{
	 struct mutex_t lock;
	 
	 uint16_t head;
	 uint16_t tail;

	 char buf[PIPE_BUFSIZE];
} __attribute__ ((packed));

void pipe_block_write(struct pipe_t *pipe, const void *buf, int n);
void pipe_block_read(struct pipe_t *pipe, void *buf, int n);

int pipe_write(struct pipe_t *pipe, const void *buf, int n);
int pipe_read(struct pipe_t *pipe, void *buf, int n);

void pipe_clear(struct pipe_t *pipe, int force);

struct pipe_t *pipe_new(void);
uint32_t pipe_share(struct pipe_t *pipe);
struct pipe_t *pipe_open(uint32_t handler);
void pipe_close(struct pipe_t *pipe);

#endif /* _EK_PIPE_H_ */
